#include "App.h"

cat::App cat::App::_current;

cat::App::App()
{
	
}

cat::App::~App()
{
	
}

cat::App& cat::App::getCurrent()
{
	return _current;
}

void cat::App::Run()
{
	_client = new net::Client();
}

void cat::App::Stop()
{
	if (_server != nullptr && _server->isRunning())
	{
		StopServer();
	}

	delete _client;
	_client = nullptr;
}

net::Server& cat::App::CreateServer()
{
	return *(_server = new net::Server());
}

void cat::App::StopServer()
{
	if (_server != nullptr)
	{
		delete _server;
		_server = nullptr;
	}
}

net::Client& cat::App::getClient()
{
	if (!isRunning())
	{
		throw "No local server defined!";
	}

	return *_client;
}

net::Server& cat::App::getServer()
{
	if (!hasServer())
	{
		throw "No local server defined!";
	}

	return *_server;
}